package Chinese.Education.Identify.controller;


import Chinese.Education.Identify.pojo.Major;
import Chinese.Education.Identify.service.MajorService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.Map;

@RestController
@RequestMapping("/major")
public class MajorController
{
    @Resource
    private MajorService majorService;
    @RequestMapping(value = "/select" , method = RequestMethod.GET)
    public Map<String, Object> selectMajor( @RequestParam(value = "page",  defaultValue = "1")  int page,
                                            @RequestParam(value = "limit", defaultValue = "10") int limit,
                                            String majorName)
    {
      Map<String, Object> map = majorService.selectMajor(page, limit, majorName);
      return map;
    }


    @RequestMapping(value = "/delete" , method = RequestMethod.POST)
    public Map<String, Object> deleteMajor(@RequestBody Map<String, String> requestData)
    {
        String majorName = requestData.get("majorName");
        if (majorName == null || majorName.isEmpty()) {
            Map<String, Object> errorResponse = new HashMap<>();
            errorResponse.put("code", 400);
            errorResponse.put("msg", "专业名称不能为空");
            return errorResponse;
        }
        return majorService.deleteMajor(majorName);
    }
    @RequestMapping(value = "/insert" , method = RequestMethod.POST)
    public Map<String, Object> insertMajor(@RequestBody Major major)
        {
            return majorService.insertMajor(major);
        }

        @RequestMapping(value = "/update" , method = RequestMethod.POST)
        public Map<String, Object> updateMajor(@RequestBody Major major)
            {
                return majorService.updateMajor(major);
            }
}
